package org.jiamandan.com.strategy.impl.tram.listener;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import io.netty.channel.Channel;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jiamandan.com.constant.BizConstant;
import org.jiamandan.com.dto.ZDBasicDto;
import org.jiamandan.com.strategy.impl.tram.IZDListenerService;
import org.jiamandan.com.utils.CommonUtil;
import org.springframework.stereotype.Service;

/**
 * @version Revision 1.0.1
 * @版权：版权所有 (c) 2021
 * @see:
 * @创建日期：2022-12-12 14:00
 * @功能说明： 嘉满电-YD下发修改充电时间应答

 * @begin
 * @修改记录:
 * @修改后版本 修改人        修改内容
 * @2022-12-01 16:50	        CWJ       	创建
 * @end
 */
@Service(value = BizConstant.CmdClass.CMD_YD_8a_SERVICE)
@AllArgsConstructor
@Slf4j
public class YDIssueChargeTimeListenerService implements IZDListenerService {


    @Override
    public void doExecute(ZDBasicDto dto, Channel client) throws Exception {
        String deviceNo = StrUtil.toString(Integer.parseInt(CommonUtil.reverseHex(dto.getDeviceNo()).substring(2), 16));
        String data = dto.getData();
        log.info("接收嘉满电-YD设置充电时间设备应答报文(CMD=8a)【"+deviceNo+"】报文:" + JSON.toJSONString(dto));
        log.info("是否设置充电时间成功(CMD=8a)【"+deviceNo+"】报文:" + switchReply(data));
    }

    private static String switchReply(String value){
        switch (value){
            case "00":
                return value+": 执行成功";
            case "01":
                return value+": 端口未在充电";
            case "02":
                return value+": 设置值小于现运行值";
            case "03":
                return value+": 无此费率模式/无此端口号";
            default:
                return value+": 故障";
        }
    }
}
